/**
 * <copyright>
 * </copyright>
 *

 */
package hu.bme.mit.androtext.nav.androNav.impl;

import hu.bme.mit.androtext.nav.androNav.AbstractActivity;
import hu.bme.mit.androtext.nav.androNav.AndroNavPackage;
import hu.bme.mit.androtext.nav.androNav.Navigation;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Navigation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link hu.bme.mit.androtext.nav.androNav.impl.NavigationImpl#getMainActivity <em>Main Activity</em>}</li>
 *   <li>{@link hu.bme.mit.androtext.nav.androNav.impl.NavigationImpl#getActivities <em>Activities</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NavigationImpl extends MinimalEObjectImpl.Container implements Navigation
{
  /**
   * The cached value of the '{@link #getMainActivity() <em>Main Activity</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMainActivity()
   * @generated
   * @ordered
   */
  protected AbstractActivity mainActivity;

  /**
   * The cached value of the '{@link #getActivities() <em>Activities</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getActivities()
   * @generated
   * @ordered
   */
  protected EList<AbstractActivity> activities;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected NavigationImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return AndroNavPackage.Literals.NAVIGATION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public AbstractActivity getMainActivity()
  {
    return mainActivity;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetMainActivity(AbstractActivity newMainActivity, NotificationChain msgs)
  {
    AbstractActivity oldMainActivity = mainActivity;
    mainActivity = newMainActivity;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AndroNavPackage.NAVIGATION__MAIN_ACTIVITY, oldMainActivity, newMainActivity);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMainActivity(AbstractActivity newMainActivity)
  {
    if (newMainActivity != mainActivity)
    {
      NotificationChain msgs = null;
      if (mainActivity != null)
        msgs = ((InternalEObject)mainActivity).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AndroNavPackage.NAVIGATION__MAIN_ACTIVITY, null, msgs);
      if (newMainActivity != null)
        msgs = ((InternalEObject)newMainActivity).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AndroNavPackage.NAVIGATION__MAIN_ACTIVITY, null, msgs);
      msgs = basicSetMainActivity(newMainActivity, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, AndroNavPackage.NAVIGATION__MAIN_ACTIVITY, newMainActivity, newMainActivity));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<AbstractActivity> getActivities()
  {
    if (activities == null)
    {
      activities = new EObjectContainmentEList<AbstractActivity>(AbstractActivity.class, this, AndroNavPackage.NAVIGATION__ACTIVITIES);
    }
    return activities;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case AndroNavPackage.NAVIGATION__MAIN_ACTIVITY:
        return basicSetMainActivity(null, msgs);
      case AndroNavPackage.NAVIGATION__ACTIVITIES:
        return ((InternalEList<?>)getActivities()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case AndroNavPackage.NAVIGATION__MAIN_ACTIVITY:
        return getMainActivity();
      case AndroNavPackage.NAVIGATION__ACTIVITIES:
        return getActivities();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case AndroNavPackage.NAVIGATION__MAIN_ACTIVITY:
        setMainActivity((AbstractActivity)newValue);
        return;
      case AndroNavPackage.NAVIGATION__ACTIVITIES:
        getActivities().clear();
        getActivities().addAll((Collection<? extends AbstractActivity>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case AndroNavPackage.NAVIGATION__MAIN_ACTIVITY:
        setMainActivity((AbstractActivity)null);
        return;
      case AndroNavPackage.NAVIGATION__ACTIVITIES:
        getActivities().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case AndroNavPackage.NAVIGATION__MAIN_ACTIVITY:
        return mainActivity != null;
      case AndroNavPackage.NAVIGATION__ACTIVITIES:
        return activities != null && !activities.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //NavigationImpl
